package com.nowcoder.code.lcof;

import com.algorithm.model.ListNode;
import com.algorithm.model.ListNodeService;

public class JZ76 {

    public static void main(String[] args) {

        ListNode listNode = ListNodeService.getByArray(new int[]{1,1});
        ListNodeService.print(new JZ76().deleteDuplication(listNode));

    }

    public ListNode deleteDuplication(ListNode pHead) {

        if (pHead == null) {
            return pHead;
        }


        ListNode res = new ListNode(-1);
        res.next = pHead;


        ListNode now = res.next;
        ListNode t = res;

        while (now != null) {
            if (now.next == null) {
                t.next = now;
                break;
            } else if (now.val != now.next.val) {
                t.next = now;
                now = now.next;
                t = t.next;
            } else {
                while (now.next != null && now.val == now.next.val) {
                    now = now.next;
                }
                if (now.next == null) {
                    t.next = null;
                    break;
                } else {
                    now = now.next;
                }
            }
        }
        return res.next;
    }

}
